﻿using System;
using System.Collections.Generic;

namespace RexToy.UI.WinForm.Pmlx
{
    class StaticResourceCollection
    {
        public Dictionary<string, object> _dict;
        public StaticResourceCollection()
        {
            _dict = new Dictionary<string, object>();
        }

        public object this[string key]
        {
            get
            {
                return _dict[key];
            }
        }

        public void AddResource(string key, object resource)
        {
            _dict.Add(key, resource);
        }

        #region IDisposable Members
        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        #endregion

        private bool _disposed;
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
                return;

            if (disposing)
            {
                foreach (object res in _dict.Values)
                {
                    IDisposable d = res as IDisposable;
                    if (d != null)
                        d.Dispose();
                }
            }

            _disposed = true;
        }

        ~StaticResourceCollection()
        {
            Dispose(false);
        }
    }
}
